/*
#Copyright (c) 2013, Philippe Bordron <philippe.bordron@gmail.com>
#
# This file is part of SIPPER.
#
# DCC is free software: you can redistribute it and/or modify
# it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DCC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU LESSER GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# along with SIPPER.  If not, see <http://www.gnu.org/licenses/>
*/
package combi.sipper.modeling.distances;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import combi.wip.sipper.modeling.Protein;
import combi.wip.sipper.modeling.genomes.Gene;
import combi.wip.sipper.modeling.genomes.Genome;

import cern.colt.matrix.DoubleMatrix2D;

public class DistanceCoexpression<G extends Gene<E>, E extends Protein> implements DistanceBetweenGenes<G> {

	private Genome<G, E> genome;
	private DoubleMatrix2D matrix;
	private Map<G, Integer> matrixRank;

	
	public DistanceCoexpression(Genome<G, E> genome, DoubleMatrix2D m, List<G> ids)
	{
		this.genome = genome;
		this.matrix = m;
		this.matrixRank = new HashMap<G, Integer>();
		int i = 0;
		for (G g : ids)
		{
			matrixRank.put(g, i);
			i++;
		}
	}
	
	
	@Override
	public double get(G g1, G g2) {
		double result = defaultResult;
		if (genome.contains(g1) && genome.contains(g2))
		{
			int x = matrixRank.get(g1);
			int y = matrixRank.get(g2);
			result = matrix.getQuick(x, y);
		}
		return result;
	}
	
	

}
